import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type WorkflowTemplateDocument = WorkflowTemplate & Document;

@Schema({
    timestamps: true,
    collection: 'workflow_templates'
})
export class WorkflowTemplate {
    @Prop({ required: true })
    name: string;

    @Prop({ required: true })
    description: string;

    @Prop({ required: true })
    category: string;

    @Prop({ type: Object, required: true })
    workflow: Record<string, any>;

    @Prop({ type: [String], default: [] })
    tags: string[];

    @Prop({ type: String, required: true })
    thumbnail: string;

    @Prop({ type: Number, default: 0 })
    likes: number;

    @Prop({ type: Number, default: 0 })
    views: number;

    @Prop({ type: Boolean, default: true })
    isActive: boolean;

    @Prop({ required: true })
    author: string;

    @Prop({ type: Object, required: true })
    defaultParams: Record<string, any>;

    @Prop({ type: [String], default: [] })
    previewImages: string[];

    @Prop({ type: Object })
    metadata: {
        modelVersion?: string;
        recommendedSettings?: Record<string, any>;
        difficulty?: string;
        estimatedTime?: number;
    };
}

export const WorkflowTemplateSchema = SchemaFactory.createForClass(WorkflowTemplate);

// 添加索引
WorkflowTemplateSchema.index({ name: 'text', description: 'text', tags: 'text' });
WorkflowTemplateSchema.index({ category: 1 });
WorkflowTemplateSchema.index({ createdAt: -1 });
WorkflowTemplateSchema.index({ author: 1 });
WorkflowTemplateSchema.index({ isActive: 1 });